

package com.c2soft.ncmxBtrade.controller;

import java.net.URI;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import lombok.extern.log4j.Log4j2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.UriComponentsBuilder;

import com.c2soft.ncmxBtrade.command.BrokerFormCommand;


@Log4j2
@Controller
@RequestMapping("/user")
public class PasswordController {
	
	@Value("#{systemProperties['ncmxServer.redirect.url']}")
	private String baseServerUrl;
	
	@Autowired
	private RestTemplate restTemplate;
	@RequestMapping(value = "/UpdatePwd", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public void buy(@RequestBody BrokerFormCommand user,HttpServletRequest req) {
		String redirectUrl = baseServerUrl+"user/UpdatePwd2";
	user.setbrokerId((String) req.getSession().getAttribute("trdUsrId"));
	restTemplate.postForObject(redirectUrl, user, BrokerFormCommand.class);
		
	}
	
@RequestMapping(value = "/getBrokerDetail",method={RequestMethod.GET,RequestMethod.POST})
	
	public @ResponseBody List clientpage(HttpServletRequest req) {
		
		String brokerId=(String) req.getSession().getAttribute("trdUsrId");
		URI redirectUrl= UriComponentsBuilder.fromUriString(baseServerUrl)
			    .path("broker/getBrokerDetail1")
			    .queryParam("brokerId", brokerId)
			    .build()
			    .toUri();
		List response=restTemplate.getForObject(redirectUrl, List.class);
		
		return response;
	}

@RequestMapping(value = "/getUserDetail",method={RequestMethod.GET,RequestMethod.POST})

public @ResponseBody List getUserDetail(HttpServletRequest req) {
	
	String userId=req.getParameter("userName");
	URI redirectUrl= UriComponentsBuilder.fromUriString(baseServerUrl)
		    .path("user/getUserDetail1")
		    .queryParam("userId", userId)
		    .build()
		    .toUri();
	List response=restTemplate.getForObject(redirectUrl, List.class);
	return response;
}
	
	@RequestMapping(value = "/UpdateTransPwd", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public void sell(@RequestBody BrokerFormCommand user,HttpServletRequest req) {
		String redirectUrl =  baseServerUrl+"user/UpdateTransPwd2";
	user.setbrokerId((String) req.getSession().getAttribute("trdUsrId"));
		restTemplate.postForObject(redirectUrl, user, BrokerFormCommand.class);
		
	}
	
	@RequestMapping(value = "/ForgetPwd", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")

	public void ForgetPwd(@RequestBody BrokerFormCommand user,HttpServletRequest req) {
		String redirectUrl = baseServerUrl+"user/ForgetPwd1";
		restTemplate.postForObject(redirectUrl, user, BrokerFormCommand.class);
	}

}
